/************** init.html **************/
function query_workplan(page) {
	sys_loading();
	var suc = '';
	$('#ptypeObjList').find('.pc').each(function () {
		suc += $(this).val() + ',';
	});
	if (suc.length > 0) {
		suc = suc.substring(0, suc.length - 1);
		var parm = $('#queryForm').serialize() + '&suc=' + suc + '&pageSize=10' + (page != null ? ('&page=' + page) : '');
	}else{
		var parm = $('#queryForm').serialize() + (page != null ? ('&page=' + page) : '');
	}
	var url = create_url('workplan-query');
	sys_record_parm('workplan',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#resultList').html(result);
		}
	});
}


function save_workplan() {
	var name = $('#name').val();
	if(name == null || name == ''){
		sys_msg('亲，还没有填名字哦！');
		return false;
	}
	var parm = $('#editForm').serialize();
	var url = create_url('workplan-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('workplan');
			} else {
				sys_msg('操作失败！')
			}
		}
	});
}

//选择用户
function selectUser_workplan() {
	var a = '';
	$('#ptypeObjList').find('input.pc').each(function () {
		a += $(this).val() + ',';
	});
	if (a.length > 0) {
		a = a.substring(0, a.length - 1);
	}
	var parm = {'a':a};
	var url = create_url("workplan-aidInit");
	$.colorbox({overlayClose:false, href:url,data:parm, close:'[关闭]', width:'1000px', height:'700px', open:true});
}

function aidQueryUser_workplan(page) {
	var oldoc = $('#old_oc').val();
	var suc = '';
	$('#selectedListBody').find('.run').each(function () {
		suc += $(this).val() + ',';
	});
	suc += oldoc;
	if (suc.length > 0 && oldoc.length == 0) {
		suc = suc.substring(0, suc.length - 1);
	}
	var parm = $('#aidQueryForm').serialize() + '&suc=' + suc + '&pageSize=10' + (page != null ? ('&page=' + page) : '');
	var url = create_url('workplan-aidList');
	sys_loading();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#aidQueryResultList').html(result);
		}
	});
}




function addUser_workplan(code, realName, on) {
	var tr = $('#tempTable').find('.rep').clone(true);
	tr.find('.rn').html(realName).end()
		.find('.on').html(on).end()
		.find('.run').val(code).end()
		.find('.un').val(realName).end()
	$('#selectedListBody').append(tr);
	aidQueryUser_workplan($('#aidQueryUserPageTxt').val());
}

function chooseUser_workplan() {
		var template = $('#tempListDiv').find('.rep');
		var ListTd = $('#ptypeObjList');
		var i = 0;
		$('#selectedListBody').find('.rep').each(function () {
			var rep = template.clone(true);
			rep.find('.title').html($(this).find('.un').val()).end()
				.find(".pc").attr({"name" : "list["  + i + "].pc", "value":$(this).find('.run').val()}).end()
				.find('.ucs').attr({'realName':"list["  + i + "].mc"}).end();
			ListTd.append(rep);
			i++;
		});
		$.fn.colorbox.close();
	}

function deleteUser_workplan(btn) {
	btn.parents('.rep').remove();
	aidQueryUser_workplan($('#aidQueryUserPageTxt').val());
}

function delete_workplan(btn, i) {
	btn.parents('.rep').remove();
}